from random import *
from utils import *
from config import *

question_templates = [
    'Please identify the pixel location of {object} in the image.',
    'In the image, locate {object} and provide its pixel coordinate.',
    'Please find {object} in the image and specify its pixel position.',
    'Find the pixel coordinate of the {object} present in the image.',
    'Locate the {object} in the image and indicate its pixel position.',
    'Identify the {object} in the image and give its pixel coordinate.',
    'Could you locate {object} in the image and list its pixel location?',
    'Please mark the pixel location of {object} in the given image.',
    'In the provided image, find {object} and detail its pixel coordinate.',
    'Find {object} within the image and record its pixel position.',
    'Locate the {object} in the image and provide its precise pixel coordinate.',
    'Identify the pixel position for {object} in the image.',
    'Please detect the {object} in the image and annotate its pixel location.',
    'In the image, point out the {object} and supply its pixel coordinate.',
    'Locate {object} on the image and indicate its pixel coordinate.',
    'Please find the {object} and specify its pixel coordinates in the image.',
    'Could you identify where {object} is located in the image by giving its pixel position?',
    'Provide the pixel coordinate of the {object} as seen in the image.',
    'In the image, determine the pixel location of {object}.',
    'Mark the image to show the exact pixel coordinate of {object}.'
]

def gen_noanchor_qa(obj_dict):
    qa = []
    for id, info in obj_dict.items():
        refs = info['exclusive_ref']
        if not info['visible'] or not info['bottom_visible'] or refs == []:
            continue
        selected_refs = []
        if len(refs) <= 2:
            selected_refs = [choice(refs)]
        else:
            selected_refs = sample(refs, k = 2)
        for ref in selected_refs:
            desc = ref_to_desc(ref)
            question = choice(question_templates).format(object = desc)
            if random() < 0.4:
                question = question + SUFFIX
            answer = f'[{format_coordinate(info)}]'
            thinking = ref_to_thinking(obj_dict, info, ref, desc)
            qa.append({
                'question': question,
                'answer': answer,
                'thinking': thinking,
            })
    return qa
